import time
from .task import *
import smtplib
from email.mime.text import MIMEText


@app.task()
def send_mail():
    time.sleep(20)
    msg_from = 'your@qq.com'  # 发送方邮箱
    passwd = 'ffff'  # 填入发送方邮箱的授权码
    msg_to = 'test@your.com'  # 收件人邮箱

    subject = "python邮件测试"  # 主题
    content = "<h1>这是我使用python smtplib及email模块发送的邮件</h1>"  # 正文
    msg = MIMEText(content, 'html')  # 第二个参数设置HTML格式发送邮件
    msg['Subject'] = subject
    msg['From'] = msg_from
    msg['To'] = msg_to
    try:
        s = smtplib.SMTP_SSL("smtp.qq.com", 465)  # 邮件服务器及端口号
        s.login(msg_from, passwd)
        s.sendmail(msg_from, msg_to, msg.as_string())
        print("邮件发送成功")
    except smtplib.SMTPException:
        print('失败')
    finally:
        s.quit()
